<include file="Index/header" />
<body>
<div class="panel admin-panel">
  <div class="panel-head" id="add"><strong><span class="icon-pencil-square-o"></span>{$title}</strong></div>
  <div class="body-content">
    <form class="form-x"  enctype="multipart/form-data" name="user">
      <div class="form-group">
        <div class="label">
          <label>权限名称：</label>
        </div>
        <div class="field">
          <input type="text" class="input w50" value="" name="node_name"  placeholder="请输入权限名称"/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span id="node_name" style="color:#F00;"></span>
          <div class="tips"></div>
        </div>
      </div>
        <div class="form-group">
            <div class="label">
                <label>控制器：</label>
            </div>
            <div class="field">
                <input type="text" class="input w50" value="" name="controller"  placeholder="请输入控制器"/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span id="controller" style="color:#F00;"></span>
                <div class="tips"></div>
            </div>
        </div>
        <div class="form-group">
            <div class="label">
                <label>方法：</label>
            </div>
            <div class="field">
                <input type="text" class="input w50" value="" name="act"  placeholder="请输入方法"/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span id="act" style="color:#F00;"></span>
                <div class="tips"></div>
            </div>
        </div>
        <div class="form-group">
            <div class="label">
                <label>分配等级：</label>
            </div>
            <div class="field">
                <select name="pid" class="input w50">
                    <option value="0" selected="selected">顶级</option>
                <foreach name="node" item="vo">
                    <option value="{$vo['id']}">{$vo['node_name']}</option>
                 </foreach>
                </select>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span id="pid" style="color:#F00;"></span>
                <div class="tips"></div>
            </div>
        </div>
        <div class="form-group">
            <div class="label">
                <label>权限描述：</label>
            </div>
            <div class="field">
                <input type="text" class="input w50" value="" name="content"  placeholder="请写描述"/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span id="content" style="color:#F00;"></span>
                <div class="tips"></div>
            </div>
        </div>
      <div class="clear"></div>
      <div class="form-group">
        <div class="label">
          <label></label>
        </div>
        <div class="field">
          <div class="button bg-main icon-check-square-o tijiao" style="cursor:pointer;"> 提交</div>
        </div>
      </div>
    </form>
  </div>
</div>

</body></html>
<script>
    //验证权限名称
    function checkNode(name,obj){
        $.ajax({
            url:'/Admin/Node/checkNodeUnique',
            type:'post',
            data:{node_name:name},
            dataType:'json',
            success:function(re){
                obj.html(re.tips);
            }
        });
    }
    //验证权限名称
    var attr_name=obj_tips='';
    $('input[name="node_name"]').blur(function(){
        attr_name=$(this).prop('name');
        obj_tips=$('#'+attr_name);
        if($(this).val()==''){
            obj_tips.html('权限名称不能为空！');
        }else{
            checkNode($(this).val(),obj_tips);
        }
    });
    //验证控制器
    var controller_name=obj_tips='';
    $('input[name="controller"]').blur(function(){
        controller_name=$(this).prop('name');
        obj_tips=$('#'+controller_name);
        if($(this).val()==''){
            obj_tips.html('控制器不能为空！');
        }
    });
    var node_name=controller_name='';
    function checkForm(){
        node_name=$('input[name="node_name"]').val();
        if(node_name==''){
            $('#node_name').html('权限名称不能为空！');
            return false;
        }
        controller_name=$('input[name="controller"]').val();
        if(controller_name==''){
            $('#controller').html('控制器不能为空！');
            return false;
        }
    }

    function postData(){
        var data={node_name:node_name,controller:controller_name};
        $.ajax({
            url:'/Admin/Node/ajaxCheckData/scene/add',
            type:'post',
            data:data,
            dataType:'json',
            success:function(re){
                if(re.error==1){
                    $.each(re.errInfo,function(key,val){
                        $('#'+key).html(val);
                    })
                    window.location.href='#mask';
                }else{
                    $('form[name="user"]').prop('action','node_add').prop('method','post');
                    $('form[name="user"]').submit();
                }
            }
        });
    }

    $('.tijiao').click(function(){
        var flag;
        flag=checkForm();//提交前的验证
        if(flag===false){
            window.location.href='#mask';
        }else{
            postData();//发送数据进行验证
        }
    });
</script>